//
//  MeSendPostController.m
//  youthNote
//
//  Created by huangrensheng on 16/7/19.
//  Copyright © 2016年 laber. All rights reserved.
//

#import "MeSendPostController.h"

@interface MeSendPostController()<UITextFieldDelegate,UITextViewDelegate>

@property (nonatomic, strong) CustomTextField *postTitle;

@property (nonatomic, strong) UITextView *postContent;

@property (nonatomic, strong) UILabel *contentPlace;//提示信息

@end

@implementation MeSendPostController

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = BACK_COLOR;
    [self createWithLeftStyle:@{@"type":@"back"} middleStyle:@{@"type":@"title",@"title":@"发帖"} rightStyle:@{@"type":@"btn",@"title":@"完成"}];
    [self initChildViews];
    [self makeConstraints];
}

- (void)initChildViews{
    self.postTitle = [[CustomTextField alloc] init];
    NSMutableAttributedString *pla = [[NSMutableAttributedString alloc] initWithString:@"请输入标题"];
    [pla addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:FONT_MIDDLE] range:NSMakeRange(0, pla.length)];
    [pla addAttribute:NSForegroundColorAttributeName value:GREY_COLOR range:NSMakeRange(0, pla.length)];
    self.postTitle.attributedPlaceholder = pla;
    self.postTitle.backgroundColor = [UIColor whiteColor];
    [self.postTitle setLayer:0 borderWidh:1 borerColor:[UIColor clearColor]];
    [self.view addSubview:self.postTitle];
    
    self.postContent = [[UITextView alloc] init];
    self.postContent.delegate = self;
    self.postContent.font = [UIFont systemFontOfSize:FONT_MIDDLE];
    self.postContent.textContainerInset = UIEdgeInsetsMake(10, 10, 0, 10);
    [self.postContent setLayer:0 borderWidh:1 borerColor:[UIColor clearColor]];
    [self.view addSubview:self.postContent];

    self.contentPlace = [[UILabel alloc] initWithFont:[UIFont systemFontOfSize:FONT_MIDDLE] TextColor:GREY_COLOR Text:@"请输入内容"];
    [self.view addSubview:self.contentPlace];
}

- (void)makeConstraints{
    __weak typeof(self) weakSelf = self;
    [self.postTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.view.mas_top).equalTo(inset(10));
        make.height.equalTo(@40);
    }];
    
    [self.postContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.postTitle.mas_bottom).equalTo(@10);
        make.bottom.equalTo(weakSelf.view.mas_bottom);
        make.leading.and.trailing.equalTo(weakSelf.view);
    }];
    
    [self.contentPlace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.postContent.mas_top).equalTo(@10);
        make.leading.equalTo(weakSelf.postContent.mas_leading).equalTo(@10);
    }];
}

#pragma mark UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView{
    self.contentPlace.hidden = YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@""]) {
        self.contentPlace.hidden = NO;
    }
}

@end
